home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-07 | 1.8 KB | 100 lines | [TEXT/PJMM] |
- unit MyPlayAsyncSound;
-
- interface
-
- procedure InitPlayAsyncSound;
- procedure FinishPlayAsyncSound;
- procedure PlayAsyncSound (theSound: Handle);
- procedure PlayAsyncSoundID (id: integer);
- procedure IdleAsyncSound;
-
- implementation
-
- uses
- Sound;
-
- var
- playing: boolean;
- finished: boolean;
- sound: handle;
- chan: SndChannelPtr;
-
- {$PUSH}
- {$D-}
- { Called at interupt level! }
- procedure ChanCallBack (chan: SndChannelPtr; cmd: SndCommand);
- var
- p: ^boolean;
- begin
- p := POINTER(cmd.param2);
- p^ := true;
- end;
- {$POP}
-
- procedure FinishSound;
- var
- oe: OSErr;
- begin
- HUnlock(sound);
- playing := false;
- finished := false;
- oe := SndDisposeChannel(chan, false);
- chan := nil;
- end;
-
- procedure PlayAsyncSound (theSound: Handle);
- var
- oe: OSErr;
- myWish: SndCommand;
- begin
- if (theSound <> nil) & (theSound^ <> nil) & not playing then begin
- chan^.qLength := stdQLength;
- oe := SndNewChannel(chan, 0, 0, @ChanCallBack);
- if oe = noErr then begin
- playing := true;
- HLock(theSound);
- oe := SndPlay(chan, theSound, true);
-
- with myWish do { set up a sound mgr command block }
- begin
- cmd := callBackCmd; { set playing to false }
- param1 := 0;
- param2 := ord(@finished);
- end; {with}
- oe := SndDoCommand(chan, myWish, false);
- { If any of these commands return with an error, we aren't going to get anywhere anyway }
- end;
- end;
- end;
-
- procedure PlayAsyncSoundID (id: integer);
- var
- sound: handle;
- begin
- if not playing then begin
- sound := GetResource('snd ', id);
- PlayAsyncSound(sound);
- end;
- end;
-
- procedure InitPlayAsyncSound;
- begin
- playing := false;
- finished := false;
- sound := nil;
- chan := nil;
- end;
-
- procedure FinishPlayAsyncSound;
- begin
- if playing then
- FinishSound;
- end;
-
- procedure IdleAsyncSound;
- begin
- if finished then
- FinishSound;
- end;
-
- end.